﻿package general
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	
	public class Teclas 
	{
		//Variables para saber si una tecla esta o no pulsada
		private var press_left:Boolean = false;
		private var press_right:Boolean = false;
		private var press_up:Boolean = false;
		private var press_down:Boolean = false;
		private var press_space:Boolean = false;
		
		//Constructor
		public function Teclas(movieclip:MovieClip) 
		{
			movieclip.stage.addEventListener(KeyboardEvent.KEY_DOWN, tecla_pulsada);
			movieclip.stage.addEventListener(KeyboardEvent.KEY_UP, tecla_quitada);
		}
		
		public function izq():Boolean 
		{
			return press_left;
		}
		
		public function der():Boolean
		{
			return press_right;
		}
		
		public function arriba():Boolean 
		{
			return press_up;
		}
		
		public function abajo():Boolean 
		{
			return press_down;
		}
		
		public function espacio():Boolean 
		{
			return press_space;
		}
		
		private function tecla_pulsada(event:KeyboardEvent):void 
		{
			if (event.keyCode == 32) 
			{
				press_space = true;
			}
			if (event.keyCode == 37) 
			{
				press_left = true;
			}
			if (event.keyCode == 38) 
			{
				press_up = true;
			}
			if (event.keyCode == 39) 
			{
				press_right = true;
			}
			if (event.keyCode == 40) 
			{
				press_down = true;
			}
		}
		
		private function tecla_quitada(event:KeyboardEvent):void 
		{
			if (event.keyCode == 32) 
			{
				press_space = false;
			}
			if (event.keyCode == 37) 
			{
				press_left = false;
			}
			if (event.keyCode == 38) 
			{
				press_up = false;
			}
			if (event.keyCode == 39) 
			{
				press_right = false;
			}
			if (event.keyCode == 40) 
			{
				press_down = false;
			}
		}
	}
}